package com.eight.cloud.excel.converter;

import cn.hutool.core.util.StrUtil;
import cn.idev.excel.converters.Converter;
import cn.idev.excel.converters.ReadConverterContext;
import cn.idev.excel.enums.CellDataTypeEnum;

import java.util.Date;

/**
 * @ClassName: DateConverter
 * @Author: TXC
 * @Date: 2025-08-06 15:53
 **/
public class DateConverter implements Converter<Date> {
    @Override
    public Date convertToJavaData(ReadConverterContext<?> context) throws Exception {
        Class<?> aClass = context.getContentProperty().getField().getType();
        CellDataTypeEnum type = context.getReadCellData().getType();
        String stringValue = context.getReadCellData().getStringValue();
        if(aClass.equals(Date.class) && type.equals(CellDataTypeEnum.STRING)  && StrUtil.isBlank(stringValue)){
            return null;
        }
  
        return Converter.super.convertToJavaData(context);
    }
}
